<?php

namespace App\Plugin\HostServer\Admin;

use App\Models\Config;
use App\Plugin\AdminBaseController;
use Illuminate\Http\Request;

class ConfigController extends AdminBaseController
{
    public $pageName = '参数配置';

    public function index()
    {

        $config_name=\request()->input('type','host_server');

        $config = config_cache($config_name,$config_name);



        $config = is_array($config) ? $config : [];
        if($tpl=\request()->input('tpl'))
        {

             $this->setModelControllerView($tpl);
        }

        return $this->display($config);
    }
    public function setModel()
    {
        return new Config();
    }

    public function store( Request $request)
    {
        $config_name=$request->input('type','host_server');
        $data=$request->all();
        if($request->input('tpl')=='banner')
        {
            if(isset($data['banner'])){
                $data['banner']=json_encode($data['banner']);
            }else
            {

                $data['banner']=json_encode([]);
            }

        }

        config_cache($config_name,  $config_name,$data);
        $this->insertLog('系统配置成功');
        return $this->returnOkApi('设置成功');

    }
}
